package com.rcl.mvvmdemo.taobao

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.rcl.mvvmdemo.domain.OnSellData
import kotlinx.coroutines.launch

class OnSellViewModel : ViewModel() {
    private val onSellRepository by lazy {
        OnSellRepository()
    }

    companion object {
        //默认第一页
        const val DEFAULT_PAGE = 1
    }

    //当前页
    private var mCurrentPage = DEFAULT_PAGE

    /**
     * 加载更多内容
     */
    fun loadMore() {

    }

    /**
     * 加载首页内容
     */
    fun loadContent() {
        this.listContentByPage(mCurrentPage)
    }

    private fun listContentByPage(page: Int) {
        viewModelScope.launch {
            val onSellList: OnSellData = onSellRepository.getOnSellList(page)
            Log.i(
                "aaaaa",
                "result size==>: ${onSellList.tbk_dg_optimus_material_response.result_list.map_data.size}"
            )
        }
    }

    /**
     * 获取发现页的分类
     */
    fun loadDiscoveryPageCategories() {
        viewModelScope.launch {
            val discoveryPageCategories = onSellRepository.getDiscoveryPageCategories()
            Log.i("aaaaa", "loadDiscoveryPageCategories result size==>: ${discoveryPageCategories.size}")
        }
    }
}